import { RouteRecordRaw } from "vue-router";
import { defineStore } from "pinia";

const visitedViews: RouteRecordRaw[] = [];

export const useTagsViewStore = defineStore({
  id: "tagsView",
  state: () => ({
    visitedViews,
  }),
  actions: {
    addView(view: RouteRecordRaw) {
      // 去重
      if (this.visitedViews.some((v) => v.path === view.path)) return;

      this.visitedViews.push(
        Object.assign({}, view, {
          title: view?.name || "tag-name",
        })
      );
    },
    deleteView(view: RouteRecordRaw) {
      const i = this.visitedViews.indexOf(view);
      this.visitedViews.splice(i, 1);
      //   this.visitedViews = this.visitedViews.filter((x) => x.path !== view.path);
    },
  },
});
